<template>
  <div>
    <el-form ref="form" :model="form">
      <el-form-item label="数据源ID">
        <el-input v-model="form.DicId"></el-input>
      </el-form-item>
      <el-form-item label="数据源Value">
        <el-input v-model="form.DicValue"></el-input>
      </el-form-item>
      <el-form-item label="数据源Text">
        <el-input v-model="form.DicName"></el-input>
      </el-form-item>
      <el-form-item label="排序号">
        <el-input v-model="form.OrderNo"></el-input>
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="form.Remark"></el-input>
      </el-form-item>
      <el-form-item label="是否启用">
        <el-select v-model="form.Enable">
          <el-option label="启用" :value="1"></el-option>
          <el-option label="禁用" :value="0"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">加入数据字典</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="ReadyDicList" style="width: 100%">
      <el-table-column prop="DicId" label="数据源ID"> </el-table-column>
      <el-table-column prop="DicValue" label="数据源Value">
        <template slot-scope="data">
          <el-input v-model="data.row.DicValue"></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="DicName" label="数据源Text">
        <template slot-scope="data">
          <el-input v-model="data.row.DicName"></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="OrderNo" label="排序号">
        <template slot-scope="data">
          <el-input v-model="data.row.OrderNo"></el-input>
        </template>
      </el-table-column>
    </el-table>

    <el-button type="primary" @click="AddDicList">保存</el-button>
  </div>
</template>

<script>
export default {
  props: {
    DicId: null,
  },
  data() {
    return {
      form: {
        DicId: this.DicId,
      },
      ReadyDicList: [],
    };
  },
  created() {
    this.GetDicList();
  },
  methods: {
    onSubmit() {
      this.ReadyDicList.push(this.form);
      this.form = {};
      this.form.DicId = this.DicId;
    },
    GetDicList() {
      this.axios
        .get(
          "http://localhost:5255/api/Ditonary/GetDictionaryListMx?Id=" +
            this.DicId
        )
        .then((res) => {
          this.ReadyDicList = res.data.Data;
        });
    },
    AddDicList() {
      var DicForm = {
        DicId: this.DicId,
        DictionaryListAdd: [],
      };
      this.ReadyDicList.forEach((x) => {
        DicForm.DictionaryListAdd.push(x);
      });
      this.axios
        .post("http://localhost:5255/api/Ditonary/AddDitonaryList", DicForm)
        .then((res) => {
          console.log(res);
          if (res.data.Success) {
            this.$message.success(res.data.ErrorInfo);
            this.$emit("CloseDicListAdd");
          } else {
            this.$message.error(res.data.ErrorInfo);
          }
        });
    },
  },
};
</script>

<style>
</style>